<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <canvas id="canvas" width="400" height="400"></canvas>
    <script src="utils.js"></script>
    <script>
        window.onload = function(){
            var canvas = document.getElementById('canvas'),
                context = canvas.getContext('2d'),
                mouse = utils.captureMouse(canvas),
                x0 = 100,
                y0 = 200,
                x2 = 300,
                y2 = 200

            canvas.addEventListener('mousemove', function(){
                context.clearRect(0,0,canvas.width, canvas.height)
                //曲线的顶点 绘制的曲线不会穿过鼠标的位置
                var x1 = mouse.x,
                    y1 = mouse.y
                //
                // var x1 = mouse.x*2 - (x0+x2)/2,
                //     y1 = mouse.y*2 - (y0+y2)/2

                context.beginPath()
                context.moveTo(x0,y0)
                
                context.quadraticCurveTo(x1,y1,x2,y2)//x1,y1为曲线的顶点 控制曲线的形状，x2,y2为曲线的终点
                context.stroke()
            })
        }
    </script>
</body>
</html>